#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int N,S1,S2,S3,R;

int H(int a, int M, int p) {
    int x = 1;
    int i;
    for (i = 0; i < M; i++) {
        x *= a;
        x = x % p;
    }
    return x;
}

int main(char * argv, int argc)
{
cout << "Secret:" << endl;
S1=rand() %20 + 2 ;
cout << S1 << endl;
int D1=S1;
S2=rand() %30 + 2;
cout << S2 << endl;
int D2=S2;
S3=rand() %100 + 10;
cout << S3 << endl;
int D3=S3;
cout << "Vvedite N=";
cin >> N;
int P=H(S1, S2, S3);
cout << "Proveraushii P=" << P << endl;
S1=0;
S2=0;
S3=0;
for (int j = 0; j <= N; j++)
{
cout << "Dokazivaushii: " << endl;
int a=j+1;
cout << "i=" << a << endl;
int PD=H(D1, D2, D3);
cout << "P=" << PD << endl;
int k=j+1;
if (k==a)
 {if (P==PD)
 R=1;
 else R=0;}
else R=0;
cout << "R=" << R << endl;

if (R==1)
{P=PD; a=a+1; cout << "Verno" << endl;}
else {j=N+1; cout << "Neverno" << endl;}
}
cout << "Vihod" << endl;
getch();
return 0;
}
